1 <!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
4 <meta http-equiv=
"Content-Type" content=
"text/html; charset=UTF-8">
5 <meta http-equiv=
"Content-Style-Type" content=
"text/css">
7 <meta name=
"Generator" content=
"Cocoa HTML Writer">
8 <meta name=
"CocoaVersion" content=
"1038">
9 <style type=
"text/css">
10 p
.p1
{margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica
}
11 p
.p2
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; min-height: 12.0px}
12 p
.p3
{margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica
; color: #0021e7}
13 p
.p4
{margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica
; min-height: 14.0px}
14 p
.p5
{margin: 0.0px 0.0px 0.0px 56.0px; text-indent: -56.0px; font: 12.0px Helvetica
}
15 p
.p6
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #bf0000}
16 p
.p7
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #0000bf}
17 p
.p8
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
}
18 span
.s1
{font: 18.0px Helvetica
}
19 span
.s2
{color: #000000}
20 span
.s3
{color: #0000ee}
21 span
.s4
{color: #0026b4}
22 span
.s5
{color: #0021e7}
23 span
.s6
{color: #002fe0}
24 span
.s7
{color: #002ef6}
25 span
.s8
{color: #0029f7}
26 span
.s9
{color: #0000bf}
27 span
.s10
{color: #606060}
28 span
.s11
{color: #007300}
29 span
.Apple-tab-span
{white-space:pre
}
33 <p class=
"p1"><span class=
"s1"><b>PlayBuf
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></b></span><b>sample playback oscillator
</b></p>
34 <p class=
"p2"><br></p>
35 <p class=
"p3"><span class=
"s2"><b>Inherits from:
</b><a href=
"../../Core/Object.html"><span class=
"s3"><b>Object
</b></span></a></span><span class=
"s4"><b> :
</b><a href=
"../../Core/Kernel/AbstractFunction.html"><span class=
"s5"><b>AbstractFunction
</b></span></a><b> :
</b><a href=
"../UGen.html"><span class=
"s6"><b>UGen
</b></span></a></span></p>
36 <p class=
"p4"><br></p>
37 <p class=
"p1">Plays back a sample resident in memory.
</p>
38 <p class=
"p4"><br></p>
39 <p class=
"p1"><b>PlayBuf.ar(numChannels, bufnum, rate, trigger, startPos, loop, doneAction)
</b></p>
40 <p class=
"p1"><b>PlayBuf.kr(numChannels, bufnum, rate, trigger, startPos, loop, doneAction)
</b></p>
41 <p class=
"p4"><br></p>
42 <p class=
"p1"><span class=
"Apple-tab-span"> </span><b>numChannels
</b> - number of channels that the buffer will be.
</p>
43 <p class=
"p1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>this must be a fixed integer. The architechture of the SynthDef
</p>
44 <p class=
"p1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>cannot change after it is compiled.
</p>
45 <p class=
"p1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>warning: if you supply a bufnum of a buffer that has a different
</p>
46 <p class=
"p1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>numChannels then you have specified to the PlayBuf, it will
</p>
47 <p class=
"p1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>fail silently.
</p>
48 <p class=
"p1"><span class=
"Apple-tab-span"> </span><b>bufnum
</b> - the index of the buffer to use
</p>
49 <p class=
"p1"><span class=
"Apple-tab-span"> </span><b>rate
</b><span class=
"Apple-converted-space"> </span>-
1.0 is the server's sample rate,
2.0 is one octave up,
0.5 is one octave down
</p>
50 <p class=
"p1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>-
1.0 is backwards normal rate ... etc. Interpolation is cubic.
</p>
51 <p class=
"p1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><b>Note:
</b> If the buffer's sample rate is different from the server's, you will need to
</p>
52 <p class=
"p1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>multiply the desired playback rate by (file's rate / server's rate). The UGen
</p>
53 <p class=
"p1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><b>BufRateScale.kr(bufnum)
</b> returns this factor. See examples below.
</p>
54 <p class=
"p1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>BufRateScale should be used in virtually every case.
</p>
55 <p class=
"p1"><span class=
"Apple-tab-span"> </span><b>trigger
</b> - a trigger causes a jump to the startPos.
<span class=
"Apple-converted-space"> </span></p>
56 <p class=
"p1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>A trigger occurs when a signal changes from
<=
0 to
> 0.
</p>
57 <p class=
"p1"><span class=
"Apple-tab-span"> </span><b>startPos
</b> - sample frame to start playback.
</p>
58 <p class=
"p1"><span class=
"Apple-tab-span"> </span><b>loop
</b><span class=
"Apple-converted-space"> </span>-
1 means true,
0 means false. this is modulate-able.
</p>
59 <p class=
"p5"><span class=
"Apple-tab-span"> </span><b>doneAction
</b> - an integer representing an action to be executed when the buffer is finished playing. This can be used to free the enclosing synth, etc. See
<a href=
"../Synth control/Envelopes/UGen-doneActions.html"><span class=
"s7">UGen-doneActions
</span></a> for more detail.
</p>
60 <p class=
"p4"><br></p>
61 <p class=
"p1"><b>See also:
</b> <a href=
"DiskIn.html"><span class=
"s8">DiskIn
</span></a>,
<a href=
"../Oscillators/BufRd.html"><span class=
"s8">BufRd
</span></a></p>
62 <p class=
"p2"><br></p>
63 <p class=
"p2"><br></p>
64 <p class=
"p2"><br></p>
65 <p class=
"p6"><span class=
"s2">s.boot
</span>// Boot the server, if you need to
<span class=
"Apple-converted-space"> </span></p>
66 <p class=
"p2"><br></p>
67 <p class=
"p6">// read a whole sound into memory
</p>
68 <p class=
"p6">// note: not *that* columbia, the first one
</p>
69 <p class=
"p6"><span class=
"s2">b =
</span><span class=
"s9">Buffer
</span><span class=
"s2">.read(s,
</span><span class=
"s10">"sounds/a11wlk01.wav"</span><span class=
"s2">);
</span>// remember to free the buffer later.
</p>
70 <p class=
"p2"><br></p>
71 <p class=
"p7">SynthDef
<span class=
"s2">(
</span><span class=
"s11">\help_PlayBuf
</span><span class=
"s2">, {
</span>| out =
0, bufnum =
0 |
</p>
72 <p class=
"p8"><span class=
"Apple-tab-span"> </span><span class=
"s9">Out
</span>.ar(out,
<span class=
"Apple-converted-space"> </span></p>
73 <p class=
"p8"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s9">PlayBuf
</span>.ar(
1, bufnum,
<span class=
"s9">BufRateScale
</span>.kr(bufnum), doneAction:
2)
</p>
74 <p class=
"p8"><span class=
"Apple-tab-span"> </span>)
</p>
75 <p class=
"p8">}).play(s, [
<span class=
"s11">\out
</span>,
0,
<span class=
"s11">\bufnum
</span>, b]);
</p>
76 <p class=
"p2"><br></p>
77 <p class=
"p1">In the above example, note how the doneAction:
2 causes the synth to free itself when the buffer reaches its end.
</p>
78 <p class=
"p4"><br></p>
79 <p class=
"p1">Note again that the number of channels must be fixed for the SynthDef. It cannot vary depending on which buffer you use.
</p>
80 <p class=
"p2"><br></p>
81 <p class=
"p2"><br></p>
82 <p class=
"p6">// loop is true
</p>
83 <p class=
"p7">SynthDef
<span class=
"s2">(
</span><span class=
"s11">\help_PlayBuf
</span><span class=
"s2">, {
</span>| out =
0, bufnum =
0 |
</p>
84 <p class=
"p8"><span class=
"Apple-tab-span"> </span><span class=
"s9">Out
</span>.ar(out,
<span class=
"Apple-converted-space"> </span></p>
85 <p class=
"p8"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s9">PlayBuf
</span>.ar(
1, bufnum,
<span class=
"s9">BufRateScale
</span>.kr(bufnum), loop:
1.0)
</p>
86 <p class=
"p8"><span class=
"Apple-tab-span"> </span>)
</p>
87 <p class=
"p8">}).play(s, [
<span class=
"s11">\out
</span>,
0,
<span class=
"s11">\bufnum
</span>, b]);
</p>
88 <p class=
"p2"><br></p>
89 <p class=
"p2"><br></p>
90 <p class=
"p2"><br></p>
91 <p class=
"p6">// trigger one shot on each pulse
</p>
92 <p class=
"p7">SynthDef
<span class=
"s2">(
</span><span class=
"s11">\help_PlayBuf
</span><span class=
"s2">, {
</span>| out =
0, bufnum =
0 |
</p>
93 <p class=
"p8"><span class=
"Apple-tab-span"> </span><span class=
"s9">var
</span> trig;
</p>
94 <p class=
"p8"><span class=
"Apple-tab-span"> </span>trig =
<span class=
"s9">Impulse
</span>.kr(
2.0);
</p>
95 <p class=
"p8"><span class=
"Apple-tab-span"> </span><span class=
"s9">Out
</span>.ar(out,
<span class=
"Apple-converted-space"> </span></p>
96 <p class=
"p8"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s9">PlayBuf
</span>.ar(
1, bufnum,
<span class=
"s9">BufRateScale
</span>.kr(bufnum), trig,
0,
0)
</p>
97 <p class=
"p8"><span class=
"Apple-tab-span"> </span>)
</p>
98 <p class=
"p8">}).play(s, [
<span class=
"s11">\out
</span>,
0,
<span class=
"s11">\bufnum
</span>, b]);
</p>
99 <p class=
"p2"><br></p>
100 <p class=
"p2"><br></p>
101 <p class=
"p6">// trigger one shot on each pulse
</p>
102 <p class=
"p7">SynthDef
<span class=
"s2">(
</span><span class=
"s11">\help_PlayBuf
</span><span class=
"s2">, {
</span>| out =
0, bufnum =
0 |
</p>
103 <p class=
"p8"><span class=
"Apple-tab-span"> </span><span class=
"s9">var
</span> trig;
</p>
104 <p class=
"p8"><span class=
"Apple-tab-span"> </span>trig =
<span class=
"s9">Impulse
</span>.kr(
<span class=
"s9">XLine
</span>.kr(
0.1,
100,
30));
</p>
105 <p class=
"p8"><span class=
"Apple-tab-span"> </span><span class=
"s9">Out
</span>.ar(out,
<span class=
"Apple-converted-space"> </span></p>
106 <p class=
"p8"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s9">PlayBuf
</span>.ar(
1, bufnum,
<span class=
"s9">BufRateScale
</span>.kr(bufnum), trig,
5000,
0)
</p>
107 <p class=
"p8"><span class=
"Apple-tab-span"> </span>)
</p>
108 <p class=
"p8">}).play(s, [
<span class=
"s11">\out
</span>,
0,
<span class=
"s11">\bufnum
</span>, b]);
</p>
109 <p class=
"p2"><br></p>
110 <p class=
"p2"><br></p>
111 <p class=
"p2"><br></p>
112 <p class=
"p2"><br></p>
113 <p class=
"p6">// mouse control of trigger rate and startpos
</p>
114 <p class=
"p8"><span class=
"s9">SynthDef
</span>(
<span class=
"s11">\help_PlayBuf
</span>, {
<span class=
"s9">arg
</span> out=
0, bufnum=
0;
</p>
115 <p class=
"p8"><span class=
"Apple-tab-span"> </span><span class=
"s9">var
</span> trig;
</p>
116 <p class=
"p8"><span class=
"Apple-tab-span"> </span>trig =
<span class=
"s9">Impulse
</span>.kr(
<span class=
"s9">MouseY
</span>.kr(
0.5,
200,
1));
</p>
117 <p class=
"p8"><span class=
"Apple-tab-span"> </span><span class=
"s9">Out
</span>.ar(out,
<span class=
"Apple-converted-space"> </span></p>
118 <p class=
"p8"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s9">PlayBuf
</span>.ar(
1, bufnum,
<span class=
"s9">BufRateScale
</span>.kr(bufnum), trig,
<span class=
"s9">MouseX
</span>.kr(
0,
<span class=
"s9">BufFrames
</span>.kr(bufnum)),
1)
</p>
119 <p class=
"p8"><span class=
"Apple-tab-span"> </span>)
</p>
120 <p class=
"p8">}).play(s, [
<span class=
"s11">\out
</span>,
0,
<span class=
"s11">\bufnum
</span>, b]);
</p>
121 <p class=
"p2"><br></p>
122 <p class=
"p2"><br></p>
123 <p class=
"p2"><br></p>
124 <p class=
"p6">// accelerating pitch
</p>
125 <p class=
"p7">SynthDef
<span class=
"s2">(
</span><span class=
"s11">\help_PlayBuf
</span><span class=
"s2">, {
</span>| out =
0, bufnum =
0 |
</p>
126 <p class=
"p8"><span class=
"Apple-tab-span"> </span><span class=
"s9">var
</span> rate;
</p>
127 <p class=
"p8"><span class=
"Apple-tab-span"> </span>rate =
<span class=
"s9">XLine
</span>.kr(
0.1,
100,
60);
</p>
128 <p class=
"p8"><span class=
"Apple-tab-span"> </span><span class=
"s9">Out
</span>.ar(out,
<span class=
"Apple-converted-space"> </span></p>
129 <p class=
"p8"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s9">PlayBuf
</span>.ar(
1, bufnum,
<span class=
"s9">BufRateScale
</span>.kr(bufnum)*rate,
1.0,
0.0,
1.0)
</p>
130 <p class=
"p8"><span class=
"Apple-tab-span"> </span>)
</p>
131 <p class=
"p8">}).play(s, [
<span class=
"s11">\out
</span>,
0,
<span class=
"s11">\bufnum
</span>, b]);
</p>
132 <p class=
"p2"><br></p>
133 <p class=
"p2"><br></p>
134 <p class=
"p2"><br></p>
135 <p class=
"p6">// sine wave control of playback rate. negative rate plays backwards
</p>
136 <p class=
"p7">SynthDef
<span class=
"s2">(
</span><span class=
"s11">\help_PlayBuf
</span><span class=
"s2">, {
</span>| out =
0, bufnum =
0 |
</p>
137 <p class=
"p8"><span class=
"Apple-tab-span"> </span><span class=
"s9">var
</span> rate;
</p>
138 <p class=
"p8"><span class=
"Apple-tab-span"> </span>rate =
<span class=
"s9">FSinOsc
</span>.kr(
<span class=
"s9">XLine
</span>.kr(
0.2,
8,
30),
0,
3,
0.6);
</p>
139 <p class=
"p8"><span class=
"Apple-tab-span"> </span><span class=
"s9">Out
</span>.ar(out,
<span class=
"Apple-converted-space"> </span></p>
140 <p class=
"p8"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s9">PlayBuf
</span>.ar(
1, bufnum,
<span class=
"s9">BufRateScale
</span>.kr(bufnum) * rate,
1,
0,
1)
</p>
141 <p class=
"p8"><span class=
"Apple-tab-span"> </span>)
</p>
142 <p class=
"p8">}).play(s, [
<span class=
"s11">\out
</span>,
0,
<span class=
"s11">\bufnum
</span>, b]);
</p>
143 <p class=
"p2"><br></p>
144 <p class=
"p2"><br></p>
145 <p class=
"p6">// zig zag around sound
<span class=
"Apple-converted-space"> </span></p>
146 <p class=
"p7">SynthDef
<span class=
"s2">(
</span><span class=
"s11">\help_PlayBuf
</span><span class=
"s2">, {
</span>| out =
0, bufnum =
0 |
</p>
147 <p class=
"p8"><span class=
"Apple-tab-span"> </span><span class=
"s9">var
</span> rate;
</p>
148 <p class=
"p8"><span class=
"Apple-tab-span"> </span>rate =
<span class=
"s9">LFNoise2
</span>.kr(
<span class=
"s9">XLine
</span>.kr(
1,
20,
60),
2);
</p>
149 <p class=
"p8"><span class=
"Apple-tab-span"> </span><span class=
"s9">Out
</span>.ar(out,
<span class=
"Apple-converted-space"> </span></p>
150 <p class=
"p8"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s9">PlayBuf
</span>.ar(
1, bufnum,
<span class=
"s9">BufRateScale
</span>.kr(bufnum) * rate,
1,
0,
1)
</p>
151 <p class=
"p8"><span class=
"Apple-tab-span"> </span>)
</p>
152 <p class=
"p8">}).play(s, [
<span class=
"s11">\out
</span>,
0,
<span class=
"s11">\bufnum
</span>, b]);
</p>
153 <p class=
"p2"><br></p>
154 <p class=
"p2"><br></p>
155 <p class=
"p8">b.free;
</p>